<template>
	<view class="back-view" @touchmove.stop.prevent="moveHandle">
		<view class="view-background"></view>
		<view class="white-view-back">
			<view class="top-back">
				<view class="top-name">关联客户</view>
				<view class="close-back" @click="closeBtnAction">
					<image class="close-img" src="../../../static/close.png"></image>
				</view>
			</view>
			<view class="top-line"></view>
			<scroll-view style="height: 390px;" scroll-y="true">
				<view v-for="(item,index) in dataList" :key="index">
					<view class="item-back" @click="clickItem(item)">
						<image class="item-img" src="../../../static/pc_customer.png"></image>
						<view class="item-name">{{item.name}}<text v-if="item.shortName">（{{item.shortName}}）</text>
						</view>
						<image class="item-arrow" src="../../../static/arrow_right.png"></image>
					</view>
				</view>
			</scroll-view>
			<view class="bottom-back">
				<view class="bottom-btn" @click="clickCustomerAction">新增</view>
			</view>
		</view>
		<addCustomer v-if="showAddCustomer" :selectItem='selectItem' :editType='editType' v-on:successBack='updataRequest()'
			:rangeList='rangeList' :statusRangeList='statusRangeList' :hopeRangeList='hopeRangeList'
			@addCustomerClose='addCustomerClose'></addCustomer>
	</view>
</template>

<script>
	import addCustomer from "@/packageC/PhonePC/customer/addCustomer.vue"
	let app = ''

	export default {
		components: {
			addCustomer
		},
		data() {
			return {
				role: '', //当前登录角色
				roleUrl: '',
				dataList: [],
				showAddCustomer: false,
				selectItem: {},
				editType: 'add',
				rangeList: [], //
				statusRangeList: [],
				hopeRangeList: [], //
			}
		},
		mounted() {
			var _this = this;
			app = getApp()
			_this.role = app.globalData.role
			_this.roleUrl = _this.$roleUrl({
				tab: _this.role
			})
			this.requestData();
			this.requestDicData();
			this.requestStatusDicData();
			this.requestHopeDicData();
		},
		methods: {
			async updataRequest() {
				this.requestData()
			},
			//网络请求
			async requestData() {
				let _this = this
				let parmas = {
					size: 10000,
				}
				console.log(parmas)
				const res = await this.$myRequest({
					url: "/client/customer/list",
					method: 'POST',
					data: parmas,
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					_this.dataList = res.data.data.list
				}
			},

			//客户类型
			async requestDicData() {
				let _this = this
				const res = await this.$myRequest({
					url: "/comm/dict/list/param_customer_type",
					method: 'GET',
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					var arr = [];
					for (var i = 0; i < res.data.data.length; i++) {
						var item = res.data.data[i]
						item.label = item.name;
						arr.push(item)
					}
					_this.rangeList = arr;
					console.log(_this.rangeList)
				}
			},
			//权限类型
			async requestStatusDicData() {
				let _this = this
				const res = await this.$myRequest({
					url: "/comm/dict/list/param_customer_perm",
					method: 'GET',
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					var arr = [];
					for (var i = 0; i < res.data.data.length; i++) {
						var item = res.data.data[i]
						item.label = item.name;
						arr.push(item)
					}
					_this.statusRangeList = arr;
					console.log(_this.statusRangeList)
				}
			},
			//组别标签
			async requestHopeDicData() {
				let _this = this
				const res = await this.$myRequest({
					url: "/comm/dict/list/param_customer_group",
					method: 'GET',
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					var arr = [];
					for (var i = 0; i < res.data.data.length; i++) {
						var item = res.data.data[i]
						item.label = item.name;
						arr.push(item)
					}
					_this.hopeRangeList = arr;
					console.log(_this.hopeRangeList)
				}
			},


			clickItem(item) {
				console.log(item)
				this.editType = 'edit'
				this.selectItem = item
				this.showAddCustomer = true;
			},


			clickCustomerAction() {
				this.editType = 'add';
				this.showAddCustomer = true
			},
			//隐藏新增客户
			addCustomerClose() {
				this.showAddCustomer = false
			},
			closeBtnAction() {
				this.$emit('associateCustomerClose')
			},
			moveHandle() {
				return true
			}

		},
	}
</script>

<style>
	.back-view {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 99;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.view-background {
		position: absolute;
		width: 100%;
		height: 100%;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.white-view-back {
		width: 552px;
		height: 500px;
		padding: 24px;
		max-height: 500px;
		background-color: white;
		margin-top: -50px;
		border-radius: 4px;
		z-index: 101;
		position: absolute;
	}

	.top-back {
		display: flex;
		justify-content: space-between;
	}

	.top-name {
		font-size: 18px;
		font-weight: normal;
		color: #333333;

	}

	.close-back {
		cursor: pointer;
		width: 20px;
		height: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.close-img {
		width: 12px;
		height: 12px;
	}

	.top-line {
		height: 1px;
		background: #EEEEEE;
		width: 100%;
		margin-top: 20px;
		margin-bottom: 20px;
	}

	.bottom-back {

		bottom: 0px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		height: 60px;
		right: 16px;
	}

	.bottom-btn {
		cursor: pointer;
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.item-back {
		height: 60px;
		width: 100%;
		display: flex;
		align-items: center;
	}

	.item-img {
		width: 24px;
		height: 24px;
		min-width: 24px;
	}

	.item-name {
		font-size: 14px;
		font-weight: 400;
		color: #333333;
		margin-left: 6px;
	}

	.item-arrow {
		width: 8px;
		height: 16px;
		min-width: 8px;
		margin-right: 20px;
		margin-left: auto;
	}
</style>
